(function(window) {
	var dispatcher = function() {
		var events = {};
		this.addEventListener = function(type, func) {
			if (type && func) {
				if (!events[type]) {
					events[type] = {};
				}
				events[type][func] = func;
			}
			return this;
		};
		this.removeEventListener = function(type, func) {
			if (type) {
				if (events[type]) {
					if (func) {
						delete events[type][func];
					} else {
						delete events[type];
					}
				}
			}
			return this;
		};
		this.sendEvent = function(type, data) {
			if (type) {
				if (events[type]) {
					var handler;
					for ( var i in events[type]) {
						handler = events[type][i];
						if (typeof handler == "string") {
							handler = window[handler];
						}
						if (typeof handler == "function") {
							handler.call(this, data);
						}
					}
				}
			}
			return this;
		};
	};
	window.dispatcher = new dispatcher();
})(window);

// jquery event dispather
(function($) {
	$.extend({
		dispather : $(this),
		events : {
			CHANGE : "change",
			RESIZE : "resize",
			ERROR : "error",
			COMPLETE : "complete"
		},
		bind : function() {
			this.dispather.bind.apply(this.dispather, arguments);
			return this;
		},
		unbind : function() {
			this.dispather.unbind.apply(this.dispather, arguments);
			return this;
		},
		sendEvent : function(type, data) {
			this.dispather.trigger(type, data);
			return this;
		}
	});
})(jQuery);
